# encoding: utf-8

class Task < ActiveRecord::Base
  belongs_to  :workpackage,
              :touch  =>  true

  has_many    :processors

  has_many    :users,
              :through => :processors

	# validations
	validates :workpackage_id,
            :presence     =>  true,
            :numericality =>  { :only_integer => true,
                                :greater_than => 0  }

  validates :name,
            :presence =>  true,
            :length   =>  { :within => 5..100, :unless => "self.name.empty?" }

  validates :planned,
            :presence     =>  true,
            :numericality =>  { :greater_than => 0, :unless => "self.planned.blank?" }

  validates :performed,
            :presence     =>  true,
            :numericality =>  { :greater_than_or_equal_to => 0, :unless => "self.performed.blank?" }

	validates :description,
            :length =>  { :within      => 5..500,
                          :allow_blank => true,
                          :allow_nil   => true  }
		
	validates :progress,
            :presence     =>  true,
            :inclusion		=>	{ :in => [0, 25, 50, 75, 100] }

	validates :status,
            :presence     =>  true,
            :inclusion    =>  { :in =>  ['initial', 'in_progress', 'delayed','finished']  }
	
end

# == Schema Information
#
# Table name: tasks
#
#  id             :integer         not null, primary key
#  workpackage_id :integer
#  name           :string(255)
#  description    :text
#  status         :string(255)     default("initial")
#  progress       :integer         default(0)
#  planned        :float
#  performed      :float           default(0.0)
#  created_at     :datetime
#  updated_at     :datetime
#

